module.exports = function(grunt) {

    /*
        Grunt installation:
        -------------------
            npm install -g grunt-cli
            npm install -g grunt-init
            npm init (creates a `package.json` file)

        Project Dependencies:
        ---------------------
            npm install grunt --save-dev
            npm install grunt-contrib-watch --save-dev
            npm install grunt-contrib-jshint --save-dev
            npm install grunt-contrib-uglify --save-dev
            npm install grunt-contrib-requirejs --save-dev
            npm install grunt-contrib-sass --save-dev
            npm install grunt-contrib-imagemin --save-dev
            npm install grunt-contrib-htmlmin --save-dev
            npm install grunt-contrib-connect --save-dev
            npm install grunt-contrib-jasmine --save-dev
            npm install grunt-template-jasmine-requirejs --save-dev
    */



    /**
    * Initialize grunt
    */
    grunt.initConfig({

        /**
         * Read package.json
         */
        pkg: grunt.file.readJSON('package.json'),


        /**
         * Set banner
         */
        banner: '/**\n' +
        '<%= pkg.title %> - <%= pkg.version %>\n' +
        '<%= pkg.homepage %>\n' +
        'Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>\n' +
        'License: <%= pkg.license %>\n' +
        '*/\n',


        /**
         * Set directory paths
         */
        dir: {
          js: 'js',
          css: 'css',
          sass: 'sass',
          img: 'img'
        },

        /**
        * Compass compiling
        * @github.com/gruntjs/grunt-contrib-compass
        */
        compass:{
            dist:{
                options:{
                    config:'config.rb',
                }
            }
        },

        
         /*
         ********************
         *Includereplace
         ********************
         */
         includereplace: {
              dist: {
                options: {
                  globals: {
                    var1: 'one',
                    var2: '.min',
                    var3: 'three'
                  }
                },
                //https://github.com/alanshaw/grunt-include-replace/pull/24   http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically
                expand: true,
                cwd: 'html/',   //下面的src是相对于html的目录. 但是编译的时候不会包含html目录,dest得到的只是文件
                src: '*.html',  //整个意思就是源文件是html/目录下的所有.html的文件 目标目录是../dev,但是只是将编译后的文件复制到dev中,不包括源文件的目录结构
                dest: '../dev/'
            }
        },

        /*
        ********************
        *grunt-sync
        ********************
        */

        sync: {
            main: {
                files: [
                    { 
                        src: ['./plugins/**/*','./venders/**/*', './js/**/*','./images/**/*','./fonts/**/*'], 
                        dest: '../dev/' 
                    }
                ],
                verbose: true // Display log messages when copying files
            }

        },

        /*
        ********************
        *watch
        ********************
        */
        watch: {
            html: {
                files:['html/**/*.html'],
                tasks:['includereplace'],
                options:{
                    livereload: true,
                    atBegin: true
                }
            },

            sass: {
                files: ['sass/**/*.{sass,scss}'],
                tasks: ['compass'],
                options: {
                    livereload: true,
                    atBegin: true
                }
            },

            others:{
                files: ['plugins/**/*','./venders/**/*','js/**/*','images/**/*','fonts/**/*'], 
                tasks: ['sync'],
                options: {
                    livereload: true,
                    atBegin: true
                }
            }
        }

});

    grunt.loadNpmTasks('grunt-contrib-compass');
    grunt.loadNpmTasks('grunt-include-replace');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-sync');

    grunt.registerTask('default', ['watch']);

};
